﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SAUlot
{
    class Controler
    {
        private ManualResetEvent endEvent;
        private Thread airplaneThread;
        private AirplaneModel airplaneModel;
        private AirplaneView airplaneView;
        //private AktorKrytyk krytyk;

        public void StartThread()
        {
            airplaneThread = new Thread(new ThreadStart(Actualize));
            airplaneThread.Start();
        }

        public void EndThread()
        {
            endEvent.Set();
            airplaneThread.Join();
        }

        //metoda do wywołania w wątku
        public void Actualize()
        {
            airplaneModel.CCMoveEvent += new Reinforcement.CCActionHandler(airplaneView.UpdateState);
            while (true)
            {
                if (endEvent.WaitOne(0, false))
                    return;

                //invokniecie delegata z modelu co by poobliczał, albo po prostu metode, wypadaloby jakies mutexy walnac w modelu dla czystosci, ale nie musi byc
                double[] tmp = new double[1];
                tmp[0] = 0.5;
                airplaneModel.CCMove(tmp);
            }
        }
    }
}
